import React, {Component} from 'react';
import {connect} from "dva";
import request from "../utils/request";

class Cinemas extends Component {

  componentDidMount() {

    request("/api/mmdb/movie/v3/list/hot.json?ct=%E6%B7%B1%E5%9C%B3&ci=30&channelId=4", {
      headers: {
        'Host': 'i.maoyan.com'
      }
    }).then(res => {
      console.log(res.data)
    })

    request("/users").then(res => {
      console.log(res)
    })


    // console.log(this.props)

    if (this.props.list.length === 0) {
      this.props.dispatch({
        type: 'CinemaList/getCinemaList'
      })
    } else {
      console.log("缓存", this.props.list)
    }
  }

  render() {
    return (
      <div>
        <ul>
          {this.props.list.map((item) =>
            <li key={item.cinemaId}>{item.name}</li>)}
        </ul>
      </div>
    );
  }
}

// const mapStateToProps = (state) => {
//   console.log(state)
//   return {
//     b: 2,
//     list: state.CinemaList
//   }
// }
const mapStateToProps = (state) => ({
  list: state.CinemaList.list
})

// cinemas 既要监听状态，又要分发 action
export default connect(mapStateToProps)(Cinemas)
